<template>
	<view style="display: flex;justify-content: center;">
		<view class="box">
			<view @click="stop">扫码加入养殖场</view>
			<view>
				<image :src="QRcodeImage"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				QRcodeImage:"",
				timer:"",
				
			};
		},
		onReady() {
			this.getQRcode();
			this.start()
			
		},
		onUnload() {
			this.stop()
		},
		onBackPress() {
			this.stop()
		},
		methods:{
			//停止定时器
			stop(){
				clearInterval(this.timer);
				console.log("清除了定时器")
			},
			//定时器
			start(){
				this.timer = setInterval(()=>{
					this.getQRcode()
				},10000)
			},
			//获取二维码
			getQRcode(){
				uni.request({
					url:this.confige.webUrl+"/farmWorker",
					data:{
					},
					header:{
						'X-Token':this.User.token
					},
					success: (res) => {
						// console.log(res)
						this.QRcodeImage = res.data.result[0].date;
						if(code==400){
							uni.showModal({
								showCancel:false,
								title:"提示",
								content:"您没绑定有养殖场！",
								success: (res) => {
									  if (res.confirm) {
									            console.log('用户点击确定');
									        }
								}
							})
						}
					}	
				})
			}
		}
	}
</script>

<style lang="less">
page{ background-color:#4AC997;}
.box{ 
	background-color: #FFFFFF;
	height: 580rpx;
	width: 500rpx;
	margin-top: 240rpx;
	border-radius: 20rpx;
	>view:nth-of-type(1){
		text-align: center;
		color: #67655e;
		font-size: 32rpx;
		padding: 10rpx;
		height: 100rpx;
	}
	>view:nth-of-type(2){
		display: flex;
		align-items: center;
		justify-content: center;
	image{
	width: 400rpx;
	height: 400rpx;}
	}
}
</style>
